package com.cheng.reggie.mapper;

import com.cheng.reggie.dto.SetmealDto;
import com.cheng.reggie.entity.Dish;
import com.cheng.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface SetmealMapper {

    //套餐管理: 查询指定id列表数据含有启用套餐数据个数
    Integer countByIds(@Param("ids") List<Long> ids);
    //套餐管理: 删除指定多个id的套餐(伪删除)
    Integer deleteByIds(@Param("ids") List<Long> ids,
                        @Param("updateUser") Long updateUser,
                        @Param("updateTime") LocalDateTime updateTime);

    //根据套餐名称查询所有套餐数据
    List<Setmeal> findAll(@Param("name") String name);

    //根据类别id查询套餐数量数量
    @Select("SELECT COUNT(*) FROM dish where category_id=#{categoryId} and is_deleted=0")
    Integer countByCid(Long categoryId);

    //保存套餐数据
    @Insert("insert  into  setmeal values (null,#{categoryId},#{name},#{price},#{status},#{code}," +
            "#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")

    //插入后获取主键
    @Options(useGeneratedKeys = true ,keyColumn = "id",keyProperty = "id")
    Integer save(SetmealDto setmealDto);

    //根据类别id和状态查询数据
    @Select("select  * from setmeal where category_id=#{categoryId} and status=#{status}")
    List<Setmeal> findBySetmealId(@Param("categoryId") Long categoryId,@Param("status") Integer status);

    //根据套餐id查询套餐数据
    Setmeal findById(Long id);

    //根据套餐id修改套餐数据
    Integer updateById(SetmealDto setmealDto);
}
